package seTOee.annotation.instance;
import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws Exception {
        Demo demo = new Demo();
        //获取Demo类中的所有方法
        Class<Demo> C = Demo.class;
        Method[] methods = C.getDeclaredMethods();
        //遍历，先判断然后获得注解对象
        for (Method m : methods){
            if (m.isAnnotationPresent(MyTest.class)){
                MyTest ma = m.getAnnotation(MyTest.class);
                //获取注解的属性值
                int num = ma.count();
                //要执行的次数
                for (int i = 0; i < num; i++) {
                    m.invoke(demo);//-->相当于demo.METHOD()
                }
            }
        }

    }
    @MyTest
    public void test1(){
        System.out.println("test1执行了");
    };
    public void test2(){
        System.out.println("test2执行了");
    };
    @MyTest(count = 3)
    public void test3(){
        System.out.println("test3执行了");
    };
    public void test4(){
        System.out.println("test4执行了");
    };

}
